package com.sdap2.entity;

import com.sdap2.common.entity.LogicEntity;
import com.sdap2.entity.enums.DeviceType;
import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import com.fasterxml.jackson.annotation.JsonIgnore;

import java.util.List;

@Data
@Entity
@Table(name = "device")
@EqualsAndHashCode(callSuper = true)
public class Device extends LogicEntity {
    
    @Column(length = 100, nullable = false)
    private String name;
    
    @Column(name = "serial_number", length = 50, nullable = false, unique = true)
    private String serialNumber;
    
    @Enumerated(EnumType.STRING)
    @Column(name = "device_type", length = 20, nullable = false)
    private DeviceType deviceType;
    
    @Column(length = 20)
    private String unit;
    
    @Column(length = 200)
    private String description;
    
    @Column(name = "monitor_url", length = 500)
    private String monitorUrl;
    
    @Column(nullable = false)
    private Integer status = 0; // 0离线,1在线
    
    @JsonIgnore
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "greenhouse_id", nullable = false,
                foreignKey = @ForeignKey(name = "device_greenhouse_fk",
                                       foreignKeyDefinition = "FOREIGN KEY (greenhouse_id) REFERENCES greenhouse (id) ON DELETE CASCADE"))
    private Greenhouse greenhouse;
} 